  <!DOCTYPE html>
<html lang="en" xmlns:th="http://www.springframework.org/schema/mvc">

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>CSR药企通</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="../favicon.ico">
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <link href="../css/login.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>

</head>

<body class="signin">
<div class="signinpanel">
    <div class="row">
        <div class="col-sm-7">
            <div class="signin-info">
                <div class="logopanel m-b">
                </div>
                <div class="m-b"></div>
                <h3>
                    欢迎使用 <strong>CSR后台管理系统</strong>
                </h3>
            </div>
        </div>
        <div class="col-sm-5">
            <form id="signupForm">
                <h3 class="text-center">用户登录</h3>
                <p class="m-t-md text-center">CSR后台管理</p>
                <input type="text" name="user_name" class="form-control uname" th:value=""/>
                <input type="password" name="password"
                       class="form-control pword m-b" th:value=""/>
                   <span id="erro" style="color: red"></span>
                <a id="login" class="btn btn-login btn-block">登录</a>
            </form>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="../js/jquery.min.js?v=2.1.4" th:src="@{/js/jquery.min.js?v=2.1.4}"></script>
<script src="../js/bootstrap.min.js?v=3.3.6" th:src="@{/js/bootstrap.min.js?v=3.3.6}"></script>

<!-- 自定义js -->
<script src="../js/content.js?v=1.0.0" th:src="@{/js/content.js?v=1.0.0}"></script>

<!-- jQuery Validation plugin javascript-->
<script src="../js/plugins/validate/jquery.validate.min.js" th:src="@{/js/plugins/validate/jquery.validate.min.js}"></script>
<script src="../js/plugins/validate/messages_zh.min.js" th:src="@{/js/plugins/validate/messages_zh.min.js}"></script>
<script src="../js/plugins/layer/layer.min.js" th:src="@{/js/plugins/layer/layer.min.js}"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#login").on('click',function(){
            $("#signupForm").submit();
        });
        validateRule();
        $("body").keydown(keyDownLogon);
    });

    $.validator.setDefaults({
        submitHandler: function () {
            login();
        }
    });

    function login() {
        $.ajax({
            type: "get",
            url: "/users/login",
            data: $('#signupForm').serialize(),
            dataType:"json",
            success: function (json) {
                if(json.code==0){
                    //alert("登录成功");
                    window.location.href="index_v1.html";
                }else{
                    //alert("登录失败"+json.message)
                    var icon = "<i class='fa fa-times-circle'></i> ";
                    $("#erro").html(icon+json.msg)
                }
            },
        });
    }

    function keyDownLogon(){
        if (event.keyCode == "13") {
            $("#login").trigger('click');
        }
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                user_name: {
                    required: true
                },
                password: {
                    required: true
                }
            },
            messages: {
                user_name: {
                    required: icon + "请输入您的用户名",
                },
                password: {
                    required: icon + "请输入您的密码",
                }
            }
        })
    }
</script>
</body>
</html>
